package com.comment.util.message;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 信息返回体
 * @param <T>
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResponseResult<T> {
    private int status;
    private String msg;
    private T data;
    private String source;

    public ResponseResult(int status, String msg) {
        this.status = status;
        this.msg = msg;
    }

    public ResponseResult(int status, String msg, T data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public static <T> ResponseResult<T> success(String msg, T data) {
        return new ResponseResult<>(1, msg, data);
    }

    public static <T> ResponseResult<T> success(T data) {
        return new ResponseResult<T>(1, "ok", data);
    }

    public static <T> ResponseResult<T> success(String msg) {
        return new ResponseResult<T>(1, msg);
    }

    public static ResponseResult<?> success() {
        return new ResponseResult<>(1, "ok", null);
    }

    public static ResponseResult<?> error(String msg) {
        return new ResponseResult<>(999, msg, null);
    }

    public static ResponseResult<?> error(String msg, Object data) {
        return new ResponseResult<>(999, msg, data);
    }

    public static ResponseResult<?> error(Object data) {
        return new ResponseResult<>(999, "error", data);
    }
}
